#ifndef _CRT_MUTEX_H_
#define _CRT_MUTEX_H_

#include <crt_core.hpp>

#ifdef __cplusplus
extern "C" {
#endif

#if (TARGET_OS == OS_WIN)

typedef struct {
    int setrobus;
    int process_shared;
    CRITICAL_SECTION cs;
    DWORD owner;
} _mutex_t;

#elif (TARGET_OS == OS_POSIX)

typedef struct {
    int setrobus;
    int process_shared;
    pthread_mutex_t mutex;
} _mutex_t;

#elif (TARGET_OS == OS_MACH)

typedef struct {
    int setrobus;
    int process_shared;
    pthread_mutex_t mutex;
} _mutex_t;

#elif (TARGET_OS == OS_UNIX)

typedef struct {
    int setrobus;
    int process_shared;
    pthread_mutex_t mutex;
} _mutex_t;

#endif

int _mutex_init(_mutex_t* lock);
int _mutex_init_recursive(_mutex_t* lock);
int _mutex_destroy(_mutex_t* lock);
int _mutex_lock(_mutex_t* lock);
int _mutex_trylock(_mutex_t* lock);
int _mutex_unlock(_mutex_t* lock);

#ifdef __cplusplus
}
#endif

#endif
